1472D - Even-Odd Game - CodeForces Solution


dp games greedy sortings *1200

Please click on ads to support us..

Python Code:

for i in range(int(input())):
    n = int(input())

    my_list = list(map(int,input().split()))

    my_list.sort()

    sum_Alice = 0
    sum_Bob   = 0
    j = 0
    i = n-1
    while i>=0:
        elem = my_list[i]

        if j%2:
            if elem%2:
                sum_Bob += elem
        else:
            if elem%2==0:
                sum_Alice += elem
        j += 1
        i -= 1

    if sum_Alice>sum_Bob:
        print("Alice")
    elif sum_Alice<sum_Bob:
        print("Bob")
    else:
        print("Tie")
        


C++ Code:

#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <cmath>
#include <limits.h>
#include <unordered_set>
#define lli long long int
#define vi vector<int>
#define vvi vector<vector<int>>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
        lli n;cin>>n;
        vector<lli>vec(n);
        lli e_sum=0,o_sum=0;
        for(lli i=0;i<n;i++)
        {
            cin>>vec[i];
        }
        sort(vec.begin(),vec.end(),greater<lli>());
        bool flag=true;
        for(lli i=0;i<n;i++)
        {
            if(flag)
            {
                flag=false;
                if(vec[i]%2==0)
                {
                    e_sum+=vec[i];
                }
            }
            else
            {
                flag=true;
                if(vec[i]%2!=0)
                {
                    o_sum+=vec[i];
                }
            }
        }
        if(e_sum>o_sum)
        {
            cout<<"Alice"<<endl;
        }
        else if(e_sum<o_sum)
        {
            cout<<"Bob"<<endl;
        }
        else{
            cout<<"Tie"<<endl;
        }
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1663D - Is it rated - 3
1311A - Add Odd or Subtract Even
977F - Consecutive Subsequence
939A - Love Triangle
755A - PolandBall and Hypothesis
760B - Frodo and pillows
1006A - Adjacent Replacements
1195C - Basketball Exercise
1206A - Choose Two Numbers
1438B - Valerii Against Everyone
822A - I'm bored with life
9A - Die Roll
1430B - Barrels
279B - Books
1374B - Multiply by 2 divide by 6
1093B - Letters Rearranging
1213C - Book Reading
1468C - Berpizza
1546B - AquaMoon and Stolen String
1353C - Board Moves
902A - Visiting a Friend
299B - Ksusha the Squirrel
1647D - Madoka and the Best School in Russia
1208A - XORinacci
1539B - Love Song
22B - Bargaining Table
1490B - Balanced Remainders
264A - Escape from Stones
1506A - Strange Table
456A - Laptops